package com.itheima.service;

import com.itheima.dao.StudentDao;
import com.itheima.domain.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class StudentService implements StudentDao {
    private static StudentDao mapper;
    static {
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = Resources.getResourceAsStream("SqlConfig.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = build.openSession(true);
         mapper = sqlSession.getMapper(StudentDao.class);
        }


    public void add(Student student) {
      mapper.add(student);
    }

    public List<Student> look() {
        List<Student> look = mapper.look();
        return look;
    }
}
